#include <bits/stdc++.h>
// 2025/02/03
// tag: 
// Author: Zhang Muen
using namespace std;

int n, ans, pos, dp[21], pre[21], mine[21];
bool g[21][21];

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> mine[i];
    for (int i = 1; i <= n; i++){
        for (int j = i + 1; j <= n; j++){
            int tmp;
            cin >> tmp;
            if (tmp)
                g[i][j] = true;
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            if (g[j][i] && dp[j] > dp[i]){
                dp[i] = dp[j];
                pre[i] = j;
            }
        }
        dp[i] += mine[i];
        if (dp[i] > ans){
            ans = dp[i];
            pos = i;
        }
    }
    stack<int> st;
    while (pos){
        st.push(pos);
        pos = pre[pos];
    }
    while (!st.empty()){
        cout << st.top() << " ";
        st.pop();
    }
    cout << endl << ans;
    return 0;
}